home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 2.toast / pc / sample code / networking / pgpuam / sources / pgpuamclientprotocol.c < prev    next >
Encoding:
Text File  |  2000-06-23  |  5.3 KB  |  205 lines

  1. /*
  2.     File:            PGPUAMclientProtocol.c
  3.  
  4.     Description:    Handles the PGPlogin Authorization Process
  5.  
  6.     Written by:    Vinnie Moscaritolo
  7.  
  8.     Copyright:    © 1998 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.     You may incorporate this sample code into your applications without
  13.     restriction, though the sample code has been provided "AS IS" and the
  14.     responsibility for its operation is 100% yours.  However, what you are
  15.     not permitted to do is to redistribute the source as "DSC Sample Code"
  16.     after having made changes. If you're going to re-distribute the source,
  17.     we require that you make it clear in the source that the code was
  18.     descended from Apple Sample Code, but that you've made changes.
  19. */
  20.  
  21. //------------------------------------------------------------------------------------
  22. #pragma mark Includes
  23. //------------------------------------------------------------------------------------
  24.  
  25. #include <Errors.h>
  26. #include <String.h>
  27. #include <A4Stuff.h>
  28. #include <Resources.h>
  29. #include <MixedMode.h>
  30. #include <PLStringFuncs.h>
  31. #include <TextUtils.h>
  32. #include "ClientUAM.h" 
  33. #include "AFPPackets.h"
  34.  
  35. #include "PGPUAMclient.h"
  36. #include "PGPUAMmsgFormat.h"
  37. #include "PGPUAMclientProtocol.h"
  38. #include "PGPUAMclientLoginDialog.h"
  39.  
  40. #define PGP_MACINTOSH 1
  41. #include "pgpErrors.h"
  42. #include "pgpKeys.h"
  43. #include "pgpUtilities.h"
  44. #include "pgpFeatures.h"
  45. #include "pgpUserInterface.h"
  46. #include "pgpHash.h"
  47. #include "pgpPublicKey.h"
  48.  
  49. #include "TPGPException.h"
  50.  
  51.  
  52. #define CAN_DO_ASYNC_OPENSESSION 0
  53. #define CAN_DO_ASYNC_SENDREQUEST 0
  54.  
  55. // ---------------------------------------------------------------------------
  56. #pragma mark Local Prototypes
  57. // ---------------------------------------------------------------------------
  58.  
  59. static  pascal void SndLoginCmdCompletion (void* context, OSStatus result);
  60.     
  61.  
  62. #pragma mark -
  63.  
  64. static pascal void SndLoginCmdCompletion (void* context, OSStatus result)
  65. {
  66.  
  67.     OSStatus*  err = (OSStatus*) context;
  68.     *err = result;
  69. }
  70.  
  71. // ---------------------------------------------------------------------------
  72. OSStatus SndLoginCmd(    ClientUAMCallbackRec     *callbacks,
  73.                                     StringPtr     serverVersion, 
  74.                                     StringPtr     uamName, 
  75.                                     StringPtr     userName,
  76.                                     StringPtr    challengeString,
  77.                                     OTAddress     *serverAddress,
  78.                                     UInt8          *replyBuffer,
  79.                                     UInt32          replyBufferSize,
  80.                                     UInt32          *actReplyBufferSize,
  81.                                     short           *sessionRefNum,
  82.                             LoginIdleProcPtr    idleProc
  83.                                         )
  84. // ---------------------------------------------------------------------------
  85. {
  86.     OSStatus        ErrNo         = kUAMError;
  87.     UAMMessage        message;
  88.     UInt8            commandBuffer[256];
  89.     UInt8            *cmdP;
  90.     OSStatus         result = 1;
  91.      
  92. // format login command message
  93.     cmdP = (UInt8*) FormatLoginCmd(commandBuffer, serverVersion, uamName, userName, challengeString );
  94.     
  95. // build OpenSession command.        
  96.     message.commandCode         = kOpenSession;
  97.     message.cmdBuffer         = commandBuffer;
  98.     message.cmdBufferSize     = cmdP - commandBuffer;
  99.     message.replyBuffer     = replyBuffer;
  100.     message.replyBufferSize = replyBufferSize;
  101.  
  102. // send OpenSession to server.
  103.         
  104. #if CAN_DO_ASYNC_OPENSESSION
  105.     DebugStr("\psend OpenSession to server");
  106.  
  107.     message.contextPtr         = &result;
  108.     message.completion         = SndLoginCmdCompletion;  
  109.  
  110.      ErrNo = CallUniversalProc(     callbacks->OpenSessionUPP, 
  111.                                 kOpenSessionProcInfo, 
  112.                                 serverAddress, 
  113.                                 nil, 
  114.                                 &message);
  115.  
  116.     if(ErrNo != noErr)
  117.     while(result == 1) 
  118.     {
  119.         if(idleProc) (idleProc)();
  120.     }
  121.          
  122.      if (ErrNo != noErr) return  ErrNo ;
  123.      
  124. #else
  125.     message.contextPtr         = nil;
  126.     message.completion         = nil;  
  127.     
  128.      result = CallUniversalProc( callbacks->OpenSessionUPP, 
  129.                                 kOpenSessionProcInfo, 
  130.                                 serverAddress, 
  131.                                 nil, 
  132.                                 &message);
  133.  
  134.  
  135. #endif
  136.  
  137.     *sessionRefNum         = message.sessionRefNum;
  138.     *actReplyBufferSize = message.replyBufferSize;
  139.     if(result != noErr) result = message.result; 
  140.     
  141.       return result;
  142. }
  143.  
  144.  
  145.  
  146.  
  147. // ---------------------------------------------------------------------------
  148. OSStatus SndLoginContinueCmd(    ClientUAMCallbackRec     *callbacks,
  149.                                     short           sessionRefNum,
  150.                                     StringPtr     answerString, 
  151.                                     UInt8          *replyBuffer,
  152.                                     UInt32          replyBufferSize,
  153.                                     UInt32          *actReplyBufferSize,
  154.                             LoginIdleProcPtr    idleProc
  155.                                         )
  156. // ---------------------------------------------------------------------------
  157. {
  158.     OSStatus        ErrNo         = kUAMError;
  159.     UAMMessage        message;
  160.     UInt8            commandBuffer[200];
  161.     UInt8            *cmdP;
  162.     OSStatus         result = 1;
  163.  
  164.      // format login Continue command message
  165.     cmdP = (UInt8*) FormatLoginContinueCmd(commandBuffer,  answerString);
  166.     
  167.     message.commandCode         = kSendRequest;
  168.     message.sessionRefNum    = sessionRefNum;
  169.     message.cmdBuffer         = commandBuffer;
  170.     message.cmdBufferSize     = cmdP - commandBuffer;
  171.     message.replyBuffer     = replyBuffer;
  172.     message.replyBufferSize = 128;
  173.  
  174. #if CAN_DO_ASYNC_SENDREQUEST
  175.     message.contextPtr         = &result;
  176.     message.completion         = SndLoginCmdCompletion;  
  177.  
  178.     // send to server.
  179.  
  180.     ErrNo = CallUniversalProc(    callbacks->SendRequestUPP, kSendRequestProcInfo,&message);
  181.                     
  182.      if(ErrNo != noErr)
  183.     while(result == 1) 
  184.     {
  185.         if(idleProc) (idleProc)();
  186.     }
  187.          
  188.      if (ErrNo != noErr) return  ErrNo ;
  189.  
  190. #else
  191.     message.contextPtr         = nil;
  192.     message.completion         = nil;  
  193.     
  194.      result =  CallUniversalProc( callbacks->SendRequestUPP, kSendRequestProcInfo,&message);
  195.  
  196. #endif
  197.  
  198.     *actReplyBufferSize = message.replyBufferSize;
  199.     if(result != noErr) result = message.result; 
  200.  
  201.      return result;
  202. }
  203.  
  204.  
  205.